package org.jeecg.modules.demo3.peijian.service.impl;


import com.baomidou.mybatisplus.extension.api.R;
import org.jeecg.modules.demo3.peijian.entity.AxhkGmRecord;
import org.jeecg.modules.demo3.peijian.entity.materials.Record;
import org.jeecg.modules.demo3.peijian.mapper.AxhkGmRecordMapper;
import org.jeecg.modules.demo3.peijian.service.IAxhkGmRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Description: 购买记录
 * @Author: jeecg-boot
 * @Date:   2021-04-20
 * @Version: V1.0
 */
@Service
public class AxhkGmRecordServiceImpl extends ServiceImpl<AxhkGmRecordMapper, AxhkGmRecord> implements IAxhkGmRecordService {

    @Autowired
    private AxhkGmRecordMapper axhkGmRecordMapper;

    @Override
    public Record AtAxhkGmRecord(String startTime, String endTime) {
        if(null != startTime && null != endTime) {
            Double m1 = 0.0;//时间范围总金额
            Double m2 = 0.0;//万联芯城供货方总金额
            Double m3 = 0.0;//立创商城供货方总金额
            Record record = new Record();
            /*String startTime = time.substring(0, 10);
            String endTime = time.substring(11, 21);*/
            List<AxhkGmRecord> recordList = axhkGmRecordMapper.getAxhkGmRecord(startTime, endTime);
            for (int i = 0; i < recordList.size(); i++) {
                Double orderQuantityMonery = recordList.get(i).getOrderQuantityMonery();
                String supplyingParty = recordList.get(i).getSupplyingParty();
                if (null == supplyingParty) {
                    Double orderQuantityMonery1 = recordList.get(i).getOrderQuantityMonery();
                    m3 = m3 + orderQuantityMonery1;
                } else {
                    Double orderQuantityMonery2 = recordList.get(i).getOrderQuantityMonery();
                    m2 = m2 + orderQuantityMonery2;
                }
                m1 = m1 + orderQuantityMonery;
            }
            //获取小数点后两位
            BigDecimal a = BigDecimal.valueOf(m1).setScale(2, BigDecimal.ROUND_HALF_UP);
            Double m1s = a.doubleValue();
            BigDecimal b = BigDecimal.valueOf(m2).setScale(2, BigDecimal.ROUND_HALF_UP);
            Double m2s = b.doubleValue();
            BigDecimal c = BigDecimal.valueOf(m3).setScale(2, BigDecimal.ROUND_HALF_UP);
            Double m3s = c.doubleValue();
            record.setAmount(m1s);
            record.setMoney1(m2s);
            record.setMoney2(m3s);
            return record;
        }else{
            return null;
        }
    }
}
